<template>
	<view class="user-coupon-list" :style="{background:pageColor}">
		<fixed :zIndex="999">
			<view class="fill-base flex-center pd-lg">
				<view class="flex-1">
					<search @input="toSearch" type="input" :padding="0" :radius="30" height="70rpx" background="#F0F0F0"
						placeholder="搜索核销门店">
					</search>
				</view>
				<view @tap.stop="showDate = true" class="flex-y-center pl-lg"><i class="iconfont iconriqi c-caption"
						style=" font-size: 44rpx; color: #333;"></i></view>
			</view>
			<view class="flex-y-center f-paragraph" style="padding:30rpx 25rpx;color:#2A2A2A"
				:style="{background:pageColor}">核销数量：<view class="text-bold" style="margin-right:68rpx"
					:style="{color:primaryColor}">
					{{list.total||0}}
				</view>抵扣金额共计：<view class="text-bold" :style="{color:primaryColor}">¥{{list.discount_cash||0}}</view>
			</view>
		</fixed>
		<view @tap.stop="$util.goUrl({url:`/agent/pages/shopstore/hx-coupon?id=${item.id}&agent=${options.agent}`})"
			class="list-item rel fill-base" :style="{marginTop:index==0?'0rpx':''}" v-for="(item,index) in list.data"
			:key="index">
			<view class="bg abs" :style="{background:primaryColor}"></view>
			<view class="flex-center rel" style="z-index: 2;">
				<view class="item-price flex-center flex-column c-base rel"
					:style="{background:`linear-gradient( 180deg, ${color} 0%, ${primaryColor} 100%)`}">
					<view class="dot-item abs fill-base radius left"></view>
					<view class="dot-item abs fill-base radius right"></view>
					<view class="flex-y-baseline f-sm-title text-bold">¥<view style="font-size:48rpx">{{item.discount}}
						</view>
					</view>
					<view class="mt-sm f-icontext">{{item.type==0?`满${item.full}元可用`:'无门槛'}}</view>
				</view>
				<view class="flex-1 ml-lg" style="color:#1F1F1F">
					<view class="f-mini-title c-title text-bold max-450 ellipsis" style="margin: 5rpx 0;">
						{{item.title}}
					</view>
					<view class="f-icontext">核销门店：{{item.store_name || '-'}}</view>
					<view class="f-icontext">核销人：{{item.hx_user_name || '-'}}</view>
					<view class="f-icontext">核销时间：{{item.use_time || '-'}}</view>
					<view class="flex-y-center f-ms-little mt-sm" style="color: #ADADAD;">使用规则<i
							class="iconfont iconxiangxiazhankai"></i>
					</view>
				</view>
			</view>
		</view>

		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1" :isCenter="true"></abnor>

		<view class="space-footer"></view>

		<w-picker mode="range" :startYear="startYear*1-10" :endYear="startYear" :value="toDay" :current="false"
			fields="day" @confirm="onConfirm($event)" :disabled-after="false" ref="day" :themeColor="primaryColor"
			:visible.sync="showDate">
		</w-picker>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				options: {},
				startYear: '',
				showDate: false,
				toDay: '',
				color: '',
				param: {
					page: 1
				},
				list: {
					data: []
				},
				loading: true,
				lockTap: false
			}
		},
		computed: mapState({}),
		onLoad(options) {
			let {
				agent = 0
			} = options
			options.agent = agent * 1
			this.options = options
			this.toDay = this.$util.formatTime(new Date(), 'YY-M-D')
			this.startYear = this.$util.formatTime(new Date(), 'YY')
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return;
			this.param.page = this.param.page + 1;
			this.loading = true;
			this.getList();
		},
		methods: {
			...mapMutations(['']),
			async initIndex(refresh = false) {
				this.color = this.$util.rgbColor(this.primaryColor)
				await this.getList()
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})
				// #ifdef H5
				if (!refresh) {
					this.$jweixin.hideOptionMenu()
				}
				// #endif
			},
			initRefresh() {
				this.param.page = 1;
				this.initIndex(true)
			},
			async getList() {
				let {
					list: oldList,
					param
				} = this
				let {
					agent
				} = this.options
				let methodKey = agent ? 'agent' : 'admin'
				let newList = await this.$api[methodKey].couponHxRecord(param);
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			toSearch(val) {
				this.param.store_name = val
				this.param.page = 1
				this.getList()
			},
			onConfirm(e) {
				let start_time = e.value[0]
				let end_time = e.value[1]
				this.param.start_time = this.$util.DateToUnix(start_time)
				this.param.end_time = this.$util.DateToUnix(end_time) + 24 * 3600 - 1
				this.initRefresh()
			},
		}
	}
</script>


<style lang="scss">
	.user-coupon-list {
		.iconshaixuanxia-1 {
			font-size: 20rpx;
			transform: scale(0.6);
			color: #CDCDCD
		}

		.list-item {
			height: 210rpx;
			margin: 20rpx 25rpx 0 25rpx;
			border-radius: 18rpx;

			.bg {
				opacity: 0.1;
				border-radius: 18rpx;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: 1;
			}

			.item-price {
				width: 200rpx;
				height: 210rpx;
				border-radius: 18rpx;
				overflow: hidden;

				.dot-item {
					width: 24rpx;
					height: 24rpx;
					top: 98rpx;
				}

				.dot-item.left {
					left: -12rpx;
				}

				.dot-item.right {
					right: -12rpx;
				}
			}

			.flex-1 {
				.f-mini-title {
					height: 42rpx;
				}

				.f-icontext {
					height: 32rpx;
				}

				.iconxiangxiazhankai {
					transform: scale(0.8);
				}
			}
		}

		.search-popup {
			width: 100%;
			padding: 0 30rpx 50rpx 30rpx;

			.title {
				font-size: 34rpx;
				color: #19293F;
			}

			.search-item {
				width: 180rpx;
				height: 68rpx;
				background: #F5F5F5;
				border-radius: 8rpx;
			}

			.search-item.abs {
				top: 0;
				left: 0;
				opacity: 0.1;
			}

			.search-item:nth-child(3n) {
				margin-right: 0;
			}

			.search-btn {
				width: 260rpx;
				height: 72rpx;
				border-radius: 15rpx;
				border: 1rpx solid #C7C7C7;
				transform: rotateZ(360deg);
			}
		}
	}
</style>